package com.lee.utils;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
/**
 * 工具类，用于获取session对象及其工厂对象
 * @author Administrator
 *
 */
public class HibernateUtil {

	private static SessionFactory sessionFactory;
	//获取session对象
	public static Session getSession(){
		return getSessionFactory().getCurrentSession();
	}
	//获取sessionfactory对象
	public static SessionFactory getSessionFactory(){
		if(sessionFactory==null||sessionFactory.isClosed()){
			sessionFactory= new Configuration().configure().buildSessionFactory();
		}
		return sessionFactory;
	}
}
